<?php
namespace quote\action;

use herosphp\bean\Beans;
use herosphp\core\Controller;
use herosphp\http\HttpRequest;
use herosphp\session\Session;
use herosphp\utils\AjaxResult;
use utils\weixin\JSSDK;
use herosphp\core\Loader;

/**
 * @author
 */
class QuoteAction extends CommonAction
{


    //品名行情
    public function product(HttpRequest $request)
    {

        $product_name = $request->getParameter('product_name');

        $date = $request->getParameter('date');

        $quoteService = Beans::get('quote.quote.service');
        $quoteAnalysisService = Beans::get('quote.analysis.service');

        $result = $quoteService->getProduct($product_name, $date);
        //增加浏览量
        if($result['id']!=''){

            $quoteAnalysisService->increase('views', 1, $result['id']);

        }else{
            die('no data!');

        }

        //获取微信分享token

        $weixin_config = getConfig('weixin_config');

        Loader::import('utils.weixin.JSSDK');

        $jssdk = new JSSDK($weixin_config['appid'], $weixin_config['appser']);

        $signPackage = $jssdk->GetSignPackage();

        $this->assign('token', $signPackage);
        $this->assign('result', $result);

        $this->setView("quote_product_detail");

    }

    //牌号行情
    public function brand(HttpRequest $request)
    {

        $brand_name = $request->getParameter('brand_name');

        $date = $request->getParameter('date');

        $quoteService = Beans::get('quote.quote.service');
        $quoteDataService = Beans::get('quote.data.service');

        $result = $quoteService->getBrand($brand_name, $date, false);
        //增加浏览量
        if($result['id']!=''){

            $quoteDataService->increase('views', 1, $result['id']);

        }else{

            die('no data!');

        }
        //行情趋势
        $searchArr['brand_name'] = $brand_name;

        $searchArr['addtime_s'] = date('Y-m-d', strtotime($date)-3600*24*6);

        $searchArr['addtime_e'] = date('Y-m-d',strtotime($date));


        $trendItems = $quoteDataService->getList(1000, 1, $searchArr);

        $trendChartData = $quoteDataService->getChartData($trendItems['items'], $searchArr['addtime_s'], $searchArr['addtime_e']);

        //获取微信分享token

        $weixin_config = getConfig('weixin_config');

        Loader::import('utils.weixin.JSSDK');

        $jssdk = new JSSDK($weixin_config['appid'], $weixin_config['appser']);

        $signPackage = $jssdk->GetSignPackage();

        $this->assign('token', $signPackage);

        $this->assign('trendChartData', $trendChartData);

        $this->assign('result', $result);
        $this->setView("quote_brand_detail");

    }


}
